<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      a {
        display: block;
        height: 100vh;
        width: 100vm;
        text-align: center;
        line-height: 80vh;
      }

      #mask {
        position: fixed;
        left: 0;
        top: 0;
        background-color: rgba(0, 0, 0, 0.2);
        width: 100vw;
        height: 100vh;
        text-align: center;
        line-height: 100vh;
      }

      .btn {
        width: 200px;
        height: 40px;
        background-color: yellowgreen;
        color: #fff;
        border: none;
        outline: none;
      }
    </style>
  </head>
  <body>
    <a href="http://www.atguigu.com">点击去尚硅谷</a>
    <div id="mask">
      <button class="btn">点我关闭遮罩</button>
    </div>

    <script>
      let btn = document.querySelector(".btn");
      let mask = document.querySelector("#mask");
      // 阻止默认行为
      // btn.addEventListener("touchstart", function (e) {
      //   e.preventDefault();
      //   mask.style.display = "none";
      // });

      // 使用click事件代替touch事件
      // btn.addEventListener("click", function (e) {
      //   mask.style.display = "none";
      // });

      // 让隐藏的目标元素延迟隐藏，延迟时间大于300ms
      btn.addEventListener("touchstart", function (e) {
        setTimeout(() => {
          mask.style.display = "none";
        }, 500);
      });
    </script>
  </body>
</html>
